<include file="public@header" />
</head>
<body>
    <div class="wrap js-check-wrap">
        <ul class="nav nav-tabs">
            <li class="active"><a href="{:url('cou/index')}">优惠券列表</a></li>
            <li><a >添加优惠券</a></li>
        </ul>
        <div class="col-md-6">
            <form  method="post" class="form-horizontal js-ajax-form margin-top-20">
                <div class="row">
                    <div class="col-md-9">
                        <input type="hidden" id="c_id" value="{$data.id}">
                        <table class="table table-bordered">
                            <tr>
                                <th width="100">使用条件</th>
                                <td>
                                    <input class="form-control" type="text" style="width: 400px;" id="cause" name="cause" value="{$data.cause}"/>
                                </td>
                            </tr>
                            <tr>
                                <th width="100">优惠额度</th>
                                <td>
                                    <input class="form-control" type="text" style="width: 400px;" name="money"  id="money" value="{$data.money}"/>
                                </td>
                            </tr>
                            <tr>
                                <th width="100">开始时间</th>
                                <td>
                                    <input class="form-control js-bootstrap-date" type="text"  id="start" style="width: 400px;"    autocomplete="off" value="{$data.s_time|date='Y-m-d',###}"/>
                                </td>
                            </tr>
                            <tr>
                                <th width="100">结束时间</th>
                                <td>
                                    <input class="form-control js-bootstrap-date" type="text"  style="width: 400px;"   id="end" autocomplete="off" value="{$data.e_time|date='Y-m-d',###}"/>
                                </td>
                            </tr>
                        </table>
                    </div>
                </div>
                <button type="button" class="btn btn-primary">提交</button>
            </form>
        </div>
    </div>
</div>
<script type="text/javascript" src="__STATIC__/js/admin.js"></script>
    <script>
        $('.btn').click(function(){
            var start=$('#start').val();
            if(start == '')
            {
                alert('您好！请选择开始时间！');
                return false;
            }
            var end=$('#end').val();
            if(end == '')
            {
                alert('您好！请选择结束时间！');
                return false;
            }
            var money=$('#money').val();
            var reg = /^[1-9]\d*$/;
            var moneyyz=reg.test(money);
            if(moneyyz == false)
            {
                alert('您好！请输入大于0的数字！');
                return false;
            }
            var cause=$('#cause').val();
            var causeyz=reg.test(cause);
            if(causeyz == false)
            {
                alert('您好！请输入大于0的数字！');
                return false;
            }
            var id=$('#c_id').val();
            $.post('{:url("cou/detailpost")}',{s_time:start,e_time:end,money:money,cause:cause,id:id},function(date){
                    if(date.msg == 1)
                    {
                        alert('添加成功');
                        window.location="{:url('cou/index')}";
                    }else{
                        alert('添加失败');
                    }
            },'json');
        })
    </script>
</body>
</html>